package modelo.armas;

import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import vista.VistaFactory;
import vista.VistaMovil;
import com.thoughtworks.xstream.XStream;
import modelo.desplazadores.DesplazadorLineaRecta;
import modelo.naves.NaveAlgo42;
import modelo.naves.EnergiaLineal;
import modelo.util.Vector;
import static modelo.SetUps.VELOCIDAD_PICKUP;
import static modelo.SetUps.VIDA_EXRA_PICKUP;

public class PickUpEnergiaCaza extends PickUp{
	
	public PickUpEnergiaCaza(Vector pos, Vector dir){
		desplazador = new DesplazadorLineaRecta(pos, dir, VELOCIDAD_PICKUP);
	}
	
	public void chocarConAlgo42(NaveAlgo42 algo42) {
		algo42.tomarEnergia(new EnergiaLineal(VIDA_EXRA_PICKUP));
		this.seguirActuando = false;		
	}

	public void persistir(String file) throws IOException{
		XStream xstream = new XStream();
		xstream.alias("PickUpEnergiaCaza", PickUpEnergiaCaza.class);
		FileWriter xmlFile = new FileWriter(file);
		xstream.toXML(this,xmlFile);
	}
	
	public PickUpEnergiaCaza(String file) throws IOException{
		XStream xstream = new XStream();
		PickUpEnergiaCaza objAux;
		xstream.alias("PickUpEnergiaCaza", PickUpEnergiaCaza.class);
		objAux = (PickUpEnergiaCaza)xstream.fromXML(new FileReader(file));
		desplazador = objAux.desplazador;
				
	}
	
	public VistaMovil getVista(VistaFactory vistaFactory){
		return vistaFactory.getVistaPickUpEnergia(this);
	}
	
}
